<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ucenter extends CI_Controller {
	
	function index(){
		//$user = $this->session->userdata('ych_user');
		$headers = apache_request_headers();
		$user_id = isset($headers['user_id'])? intval($headers['user_id']) : 0;
		$token = isset($headers['token'])? $headers['token'] : '';
		$token_key = 'token_'.$user_id;
		$token_val = $this->mycache->get($token_key);

		if($user_id && $token == $token_val){
			$this->load->model('User_model', 'user');
			$user = $this->user->get_by_uid($user_id);
			
			//VIP
			$this->load->model('User_vip_model');
			$vipInfo = $this->User_vip_model->get_by_uid($user['user_id']);
			//资金账户
			$this->load->model('Account_model');
			$accountInfo = $this->Account_model->get_account($user['user_id']);
			//积分
			$this->load->model('Credit_model');
			$creditInfo = $this->Credit_model->get_row($user['user_id']);
			//最近回款时间
			$this->load->model('Borrow_model');
			$newlyCollection = $this->Borrow_model->first_collection_time($user['user_id']);
			$retUser = array(
				'user_id' => $user['user_id'],
				'username' => $user['username'],
				'email' => $user['email'],
				'realname' => $user['realname'],
				'phone' => $user['phone'],
				//'qq' => $user['qq'],
			);
			
			$data['userInfo'] = $retUser;
			//用户VIP到期时间 --为空则表示用户不是VIP
			$data['vipTime'] = $vipInfo['vip_verify_time']>0?date('Y-m-d', $vipInfo['vip_verify_time'] + 3600*24*365):'';
			$data['accountInfo'] = $accountInfo;//用户资金详情
			$data['creditValue'] = $creditInfo['credit_value'];//用户积分
			//用户最近收款时间
			$data['newCollection'] = $newlyCollection>0?date('Y-m-d', $newlyCollection):'无';
			$data['code'] = 0;
			echo json_encode($data);
		}else{
			$ret['msg'] = '请先登录';
			$ret['code'] = 1;
			echo json_encode($ret);exit;
		}
	}
	
}